<template>
	<view class="main_bg">
		<app-header title="维修"></app-header>
		<view class="btns flex-c" :style="{height:scrollHeight}">
			<view class="btns_son flex-c" @click="navToRepair()"><u-image src="/static/images/s1.png" mode="aspectFit"
					width="68rpx" height="68rpx"></u-image> 维修工单</view>
			<view class="btns_son flex-c" @click="navToInspection()"><u-image src="/static/images/s2.png"
					mode="aspectFit" width="68rpx" height="68rpx"></u-image> 巡检工单</view>
		</view>

	</view>
</template>

<script>
	const systemInfo = uni.getSystemInfoSync();
	const safeArea = systemInfo.safeArea;
	export default {
		data() {
			return {
				device_id: 0,
			}
		},
		computed: {
			scrollHeight() {
				return 'calc(100vh - 100rpx)'
			},
		},
		onLoad(option) {
			this.device_id = option.device_id
		},
		methods: {
			navToRepair() {
				uni.showLoading({
					title: 'loading',
					mask: true
				})
				this.$http.post('/data/api.auth.User/companyMaintenancelists', { device_id: this.device_id }).then(res => {

					if (res.data.page.total == 0) {
						this.$func.tips('此设备未分配给您，请联系管理员')
					} else {
						this.$http.post('/data/api.auth.User/companyMaintenancelists', {
							device_id: this.device_id,
							member_status: 1
						}).then(res => {
							if (res.data.page.total == 0) {
								this.$func.tips('此设备已维修完成')
							} else {
								this.$func.atUrl('/pages_worker/repair/repair?device_id=' + this
									.device_id);
							}
							uni.hideLoading()
						}).catch(() => {
							uni.hideLoading()
						})
					}
				}).catch(() => {
					uni.hideLoading()
				})

			},
			navToInspection() {
				uni.showLoading({
					title: 'loading',
					mask: true
				})
				this.$http.post('/data/api.auth.User/companyInspectionList', { device_id: this.device_id }).then(res => {
				
					if (res.data.page.total == 0) {
						this.$func.tips('此设备未分配给您，请联系管理员')
					} else {
						this.$http.post('/data/api.auth.User/companyInspectionList', {
							device_id: this.device_id,
							inspection_status: '0'
						}).then(res => {
							if (res.data.page.total == 0) {
								this.$func.tips('此设备已巡检完成')
							} else {
								this.$func.atUrl('/pages_worker/inspection/inspection?device_id=' + this.device_id);
							}
							uni.hideLoading()
						}).catch(() => {
							uni.hideLoading()
						})
					}
				}).catch(() => {
					uni.hideLoading()
				})
				 
			 
			},
		}
	}
</script>

<style scoped lang="scss">
	.btns {
		flex-direction: column;

		.btns_son {
			width: 424rpx;
			height: 152rpx;
			background: rgba(223, 229, 255, 1);
			border-radius: 20rpx;
			font-size: 36rpx;
			color: #4F6FF6;

			&:nth-child(2) {
				background: rgba(255, 231, 217, 1);
				color: #F68C4F;
				margin-top: 140rpx;
			}
		}

	}
</style>